package com.jbm.jbmsupplier.zp.FactouryActivity.FacturyChatBaseAdapter;

import android.content.Context;
import android.media.MediaPlayer;
import android.widget.LinearLayout;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.zp.adapters.ChatMsgViewAdapter;
import com.jbm.jbmsupplier.zp.entity.ChatMsgEntity;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.io.IOException;
import java.util.List;

/**
 * Created by 家帮忙 on 2017/7/17.
 */

public class AdapterSendAudio implements ChatBaseInterfaces {
    @Override
    public void setDataAdapter(ChatMsgViewAdapter.ViewHolder viewHolder, int position, int type, List<ChatMsgEntity> coll, String stShowSendTime, Context context, int toid) {
        viewHolder.tvUserName.setText(coll.get(position).getName());
        viewHolder.tvSendTime.setText(stShowSendTime);
        viewHolder.av_userhead.setTag(position+"");
        viewHolder.image_shibai.setTag(position+"");
        if (coll.get(position).getHead_portrait()==null||coll.get(position).getHead_portrait().equals("")){
            viewHolder.iv_userheads.setImageDrawable(context.getResources().getDrawable(R.mipmap.pic));
        }else {
            ImageOptions i=new ImageOptions.Builder().setCircular(true).build();
            x.image().bind(viewHolder.iv_userheads,coll.get(position).getHead_portrait(),i);}
        viewHolder.av_userhead.setImageDrawable(context.getResources().getDrawable(R.mipmap.vcs));
        try {
            MediaPlayer mMediaPlayesr = new MediaPlayer();
            mMediaPlayesr.reset();
            mMediaPlayesr.setDataSource(coll.get(Integer.parseInt(viewHolder.av_userhead.getTag()+"")).getMediaName());
            mMediaPlayesr.prepare();
            int a=mMediaPlayesr.getDuration()/1000;
            viewHolder.tv_miaoshu.setText(a+"″");
            if (a<5){
                LinearLayout.LayoutParams layout=new LinearLayout.LayoutParams(160,LinearLayout.LayoutParams.WRAP_CONTENT);
                viewHolder.vodiu_layout.setLayoutParams(layout);
            }else
            if (a>=5&&a<10){
                if(viewHolder.vodiu_layout instanceof LinearLayout){
                    LinearLayout.LayoutParams layout=new LinearLayout.LayoutParams(250,LinearLayout.LayoutParams.WRAP_CONTENT);
                    viewHolder.vodiu_layout.setLayoutParams(layout);
                }
            }else if (a>=10&&a>10){
                LinearLayout.LayoutParams layout=new LinearLayout.LayoutParams(400,LinearLayout.LayoutParams.WRAP_CONTENT);
                viewHolder.vodiu_layout.setLayoutParams(layout);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
